package com.lehecai.core.api.event;

import com.lehecai.core.EnabledStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 */
public class ShowOrderSetting extends AbstractApiResultBean {


	public static final String SET_TITLE = "title";
	public static final String SET_URL = "url";
	public static final String SET_TID = "tid";
	public static final String SET_STATUS = "status";


	private Long tid;
	private String title;
	private String url;
	private EnabledStatus status;

	public static ShowOrderSetting convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		ShowOrderSetting showOrderSetting = new ShowOrderSetting();
		showOrderSetting.title = getString(object, "title");
		showOrderSetting.url = getString(object, "url");
		showOrderSetting.tid = getLong(object, "tid");
		showOrderSetting.status = EnabledStatus.getItem(getInt(object, "status"));
		return showOrderSetting;
	}
	
	public static List<ShowOrderSetting> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<ShowOrderSetting> list = new ArrayList<ShowOrderSetting>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public Long getTid() {
		return tid;
	}

	public void setTid(Long tid) {
		this.tid = tid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public EnabledStatus getStatus() {
		return status;
	}

	public void setStatus(EnabledStatus status) {
		this.status = status;
	}
}
